<?php

class Listener_Fenxiao_Order extends Listener_Base
{
    public function handle($args)
    {
        $self       = new self();
        $self->args = $args;
        //判断队列是否开启,如果开启则把任务推送到队列
        if ($self->queue_status) {
            Queue::in('default', Listener_Fenxiao_Order::class, $args);
        } else {
            $self->perform();
        }
    }

    public function perform()
    {
        $order = $this->args['order'] ?? $this->args;
        St_Log::write('分销订单返佣', array('status' => $order['status']), "event/order_finished/log");
        $res = Model_Fenxiao_Commission::pay_commission($order);
        St_Log::write('分销订单返佣', array('status' => $order['status'], 'ordersn' => $order['ordersn'], 'result' => $res), 'event/order_created/log');
    }

}